package com.pachong.android.framework.share;

import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
import android.text.TextUtils;
import android.view.Gravity;

import com.cncn.youmengsharelib.ShareData;
import com.pachong.android.framework.R;


/**
 * 分享界面
 *
 * @Author: PengWeiwei
 * @E-mail: pengveivei@sina.cn
 * @CreateDate: 2016-04-07
 * @Version: 1.0.0
 */
@SuppressLint("ValidFragment")
public class SharePlatformsFragment extends BaseShareFragment {


    @SuppressLint("ValidFragment")
    public SharePlatformsFragment(String title, String content, Bitmap imgBmp, String targetUrl) {
        super(title, content, imgBmp, targetUrl);
    }

    @SuppressLint("ValidFragment")
    public SharePlatformsFragment(String title, String content, String imageUrl, String targetUrl) {
        super(title, content, imageUrl, targetUrl);
    }

    @SuppressLint("ValidFragment")
    public SharePlatformsFragment(ShareData shareData) {
        super(shareData);
    }


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setGravity(Gravity.BOTTOM);
    }

    public @LayoutRes
    int getShareLayoutId() {
        return R.layout.fragment_base_share_platforms;
    }

    /**
     * 设置Dialog的位置
     *
     * @param gravity
     */
    public void setGravity(int gravity) {
        if (getDialog() != null) {
            getDialog().getWindow().setGravity(gravity);
        }
    }


    //region 测试代码、使用例子
    public static void showShareFragment(FragmentActivity activity, String title, String content, String imgUrl, String targetUrl) {

//        imageUrl = "http://pic24.nipic.com/20121025/11197132_095434613172_2.jpg";
//        targetUrl = "http://pic24.nipic.com/20121025/11197132_095434613172_2.jpg";
        if (TextUtils.isEmpty(title)) {
            title = "萌都";
        }

        if (TextUtils.isEmpty(content)) {
            content = "萌都";
        }

        ShareData info;
        if (TextUtils.isEmpty(imgUrl)) {
            Bitmap bmp = BitmapFactory.decodeResource(activity.getResources(), com.cncn.youmengsharelib.R.drawable.ic_launcher);
            info = new ShareData(title, content, bmp, targetUrl);
        } else {
            info = new ShareData(title, content, imgUrl, targetUrl);
        }
        showShareFragment(activity, info);
    }


    public final static BaseShareFragment showShareFragment(FragmentActivity activity, ShareData info) {
        BaseShareFragment shareFrag = new SharePlatformsFragment(info.getTitle(), info.getContent(), info.getImageUrl(), info.getTargetUrl());
        shareFrag.setStyle(DialogFragment.STYLE_NO_TITLE, com.cncn.youmengsharelib.R.style.ShareDialogStyle);
        shareFrag.show(activity.getSupportFragmentManager(), "");
        return shareFrag;
    }


    public static BaseShareFragment testShowPlatforms(FragmentActivity activity) {
        String imageUrl = "http://pic24.nipic.com/20121025/11197132_095434613172_2.jpg";
        String targetUrl = "http://pic24.nipic.com/20121025/11197132_095434613172_2.jpg";

        ShareData info = new ShareData(imageUrl, "TiTLE", "content", targetUrl);
        return showShareFragment(activity, info);
    }
/*
    public static void testShareQQ(FragmentActivity activity) {
        String imageUrl = "http://pic24.nipic.com/20121025/11197132_095434613172_2.jpg";
        String targetUrl = "http://pic24.nipic.com/20121025/11197132_095434613172_2.jpg";

        ShareData shareInfo = new ShareData(imageUrl, "TiTLE", "content", targetUrl);
        shareQQ(activity, shareInfo, createShareCbListener(activity));
    }*/

}
